
package cz.muni.fi.PA165.musiclibrarybackend.dao;

import cz.muni.fi.PA165.musiclibrarybackend.entities.User;
import java.io.Serializable;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;


@Repository
public class UserDAOImpl implements UserDAO, Serializable {
    
    @PersistenceContext
    private EntityManager entityManager;

    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
    
    public void createUser(User user) {
        if (user==null){
            throw new IllegalArgumentException("user is null");
        }
        if (user.getName() == null ) {
            throw new IllegalArgumentException("user wihtout name");
        }
        if (user.getPassword() == null ) {
            throw new IllegalArgumentException("user wihtout password");
        }
        entityManager.persist(user);

    }

    public User getUser(String name) {
        if(name == null){
              throw new IllegalArgumentException("name is null");
        }
        User user = entityManager.find(User.class, name);
        return user;
    }






    
}
